<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientAction_comment extends KBClientAction_common
{

	function &execute($controller, $manager) {
	
		// need to login
		if(!$manager->is_registered && $manager->getSetting('allow_comments') == 2) { 
			$controller->go('login', $this->category_id, $this->entry_id, 'comment');
		}
		
		// if not allowed
		if(!$manager->getSetting('allow_comments')) {
			$controller->go('entry', $this->category_id, $this->entry_id);
		}
		
		
		$view = &$controller->getView();
	
		if(isset($this->rp->submit)) {
			
			$errors = $view->validate($this->rp->vars, $manager);
			//$flood = $manager->isFlood();
			
			if($errors) {
				$this->rp->stripVars(true);
				$view->setErrors($errors); 
				$view->setFormData($this->rp->vars);
			
			//} elseif($flood) {
			//	$this->rp->stripVars(true);
			//	$view->setFormData($this->rp->vars);
			//	$view->msg_id = 'flood_comment';
			
			} else {
				
				if($manager->is_registered) {
					$msg = ($manager->getSetting('comment_policy') != 2) ? 'comment_posted' : 'comment_wait';
					$active = ($manager->getSetting('comment_policy') != 2) ? 1 : 0;
				} else {
					$msg = ($manager->getSetting('comment_policy') == 1) ? 'comment_posted' : 'comment_wait';
					$active = ($manager->getSetting('comment_policy') == 1) ? 1 : 0;
				}
				
				$this->rp->stripVars();
				$manager->addComment($this->entry_id, $this->rp->vars, $active);
				$controller->go('success_go', $this->category_id, $this->entry_id, $msg);
			}
		}
		
		return $view;
	}
	
}
?>